<?php

namespace App\Http\Controllers\Blog;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\Cate;
use App\Models\Article;

class IndexController extends Controller
{
    protected $model_article;
    protected $model_cate;
    protected $page;

    public function __construct(Cate $cate, Article $article)
    {
        $this->model_article = $article;
        $this->model_cate = $cate;
        $this->page = 16;
    }


    public function index($cate_id = null)
    {
        if (is_numeric($cate_id)) {
            $condition = [
                ['cate_id', 'like' , '%,'.$cate_id.',%']
            ];
        } else {
            $condition = [];
        }
        $articles = $this->model_article->getBlogList($this->page, $condition);
        return view('blog.index', ['articles' => $articles]);
    }
}
